<?php
/**
 * User: lie
 * Date: 2020-11-07 21:34
 * description:
 */
?>
<form action="" method="post">
    我要购买 <input type="text" size="2" value="1" name="num">件
    <input type="submit" name="sub" value="加入购入车">
    <input type="submit" name="sub1" value="结账">
    <input type="submit" name="sub2" value="首页">
</form>

<?php
    if ($_POST['sub2']){
        echo "<script>window.location.href='index.php'</script>";
    }
    if ($_POST['sub']){
        $str = explode("#", $_SESSION[id]);
        include('conn.php');
        $sql = "INSERT INTO tb_shop (tTbName, tTbNum, tTbMoney, tTbMoneyOther, tTbOther) VALUES('$str[0]', '$str[1]', '$str[2]', '$str[3]', '$str[4]')";
        if ($mysqli->query($sql)){
            $mysqli->close($mysqli);
            echo "<script>alert('已加入购物车')</script>";
        }
    }
    if ($_POST['sub1']){
        require_once('conn.php');
        $sq = "SELECT * FROM tb_shop";
        $result = $mysqli->query($sq);
?>
    <form action="table.php" method="post">
        <input type="submit" name="sub3" value="删除">
    </form>
<?php
    while ($obj = $result->fetch_object()){
        for ($i = 0; $i < 6; $i++){
?>
            <tr>
                <td> <?php echo $obj->$i; ?></td>
            </tr>
<?php
    }
?>
<a href="money.php"><img src="img/cover.jpg" alt=""></a>

<?php
    }
    }
    ?>
